#include "cc.h"
#include "bsp_clk.h"
#include "bsp_led.h"
#include "bsp_delay.h"
#include "bsp_beep.h"
#include "bsp_gpio.h"
#include "bsp_key.h"

int main(void)
{

	static uint8_t led_state = 1;
	static uint8_t beep_state = 0;
	static uint8_t beep_on = OFF;
	// int beep_state = 0;
	// int	beep_on = OFF;
	int i = 0;
	int key;

	clk_init();		/* 使能所有外设时钟 */
	led_init();		/* led gpio 初始化 */
	beep_init();	/* beep gpio 初始化 */
	key_init();		/* key gpio 初始化 */


    while(1){

		// if(key_release==1 && key_getvalue()==1){
		// 	key_release = 0;
		// 	beep_state = !beep_state;
		// 	beep_switch(beep_state);
		// }
		// else if(key_getvalue() == 0){
		// 	key_release = 1;
		// }

		key = key_getvalue();
		if(key){
			switch(key)
			{
				case KEY0_VALUE:
					beep_state = !beep_state;
					//beep_switch(beep_state);
					break;
			}
		}

		if(beep_state == 1)
		{
			beep_on = !beep_on;
			beep_switch(beep_on);
		}
		else{
			beep_switch(OFF);
		}

		delay(100);

		i++;
		if(i == 5){	/* 50*10 = 500ms */
			led_state = !led_state;
			led_switch(LED_0, led_state);
			i = 0;
		}
    }

    return 0;
}